<include file="Public/header" />
<title>添加商品</title>
</head>
<body>
<div class="pd-20">

	<table class="table table-border table-bordered table-bg">

		<tbody>
			<tr class="text-c">
				<td width="15%" class="text-r" style="background-color:#f5f5f5">订单编号</td>
				<td class="text-l">
					<input type="hidden" class="input-text" value="<{$detail.order_no}>" placeholder="订单编号" id="order_no" name="order_no">
					<input type="text" class="input-text" value="<{$detail.order_no}>" placeholder="订单编号"  disabled="disabled">
				</td>
				<td width="15%" class="text-r" style="background-color:#f5f5f5">申请部门</td>
				<td class="text-l">
					<select  class="input-text" id="section_no" name="section_no">
						<option value="0">请选择</option>
						<volist name="section_list" id="vo">
							<option value="<{$vo.no}>" <if condition="$vo['no'] eq $detail['section_no']">selected</if>><{$vo.name}></option>
						</volist>
					</select>
				</td>						
			</tr>
			<tr class="text-c">
					<td width="15%" class="text-r" style="background-color:#f5f5f5">制单人：</td>
					<td class="text-l">
						<select  class="input-text people_make_no" id="people_make_no" name="people_make_no">
							<option value="0">请选择</option>
							<volist name="personnel_list" id="vo">
								<option value="<{$vo.no}>" <if condition="$vo['no'] eq $detail['people_make_no']">selected</if>><{$vo.name}></option>
							</volist>
						</select>
					</td>
					<td width="15%" class="text-r" style="background-color:#f5f5f5">业务员：</td>
					<td class="text-l">
						<select  class="input-text people_purchasing_no" id="people_purchasing_no" name="people_purchasing_no">
							<option value="0">请选择</option>
							<volist name="personnel_list" id="vo">
								<option value="<{$vo.no}>" <if condition="$vo['no'] eq $detail['people_purchasing_no']">selected</if>><{$vo.name}></option>
							</volist>
						</select>
					</td>						
			</tr>
			<tr class="text-c">
					<td width="15%" class="text-r" style="background-color:#f5f5f5">往来单位：</td>
					<td class="text-l">
						<select  class="input-text contacts_company_no" id="contacts_company_no" name="contacts_company_no">
							<option value="0">请选择</option>
							<volist name="company_list" id="vo">
								<option value="<{$vo.no}>" <if condition="$vo['no'] eq $detail['contacts_company_no']">selected</if>><{$vo.name}></option>
							</volist>
						</select>
						
					</td>
					<td width="15%" class="text-r" style="background-color:#f5f5f5">运输方式：</td>
					<td class="text-l">
						<select  class="input-text transport_cate" id="transport_cate" name="transport_cate">
							<option value="<{$detail['transport_cate']}>">
							<if condition="$detail['transport_cate'] eq 1">
							自提
							</if>
							<if condition="$detail['transport_cate'] eq 2">
							第三方物流
							</if>
							<if condition="$detail['transport_cate'] eq 3">
							送货
							</if>
							</option>
							<option value="0">请选择</option>
							<option value="1">自提</option>
							<option value="2">第三方物流</option>
							<option value="3">送货</option>
						</select>
						<if condition="$detail['transport_cate'] eq 2">
						<input type="text" name="logistics_no" class="input-text" value="<{$detail.logistics_no}>" placeholder="运单号">
						<else />
						<input type="text" name="logistics_no" style="display:none" class="input-text" value="" placeholder="运单号">
						</if>
					</td>						
			</tr>
			<tr class="text-c uhide">
					<td width="15%" class="text-r" style="background-color:#f5f5f5">客户姓名：</td>
					<td class="text-l">
						<input type="text" class="input-text user_name" value="<{$detail.user_name}>" placeholder="客户姓名" name="user_name">
					</td>
					<td width="15%" class="text-r" style="background-color:#f5f5f5">省：</td>
					<td class="text-l" style="width:35%;">
						<input type="text" class="input-text" value="<{$detail.province}>" placeholder="省" name="province">
					</td>						
			</tr>
			<tr class="text-c uhide">
					<td width="15%" class="text-r" style="background-color:#f5f5f5">市：</td>
					<td class="text-l">
						<input type="text" class="input-text user_name" value="<{$detail.city}>" placeholder="市" name="city">
					</td>
					<td width="15%" class="text-r" style="background-color:#f5f5f5">区/县：</td>
					<td class="text-l" style="width:35%;">
						<input type="text" class="input-text" value="<{$detail.area}>" placeholder="区/县" name="area">
					</td>						
			</tr>
			<tr class="text-c uhide">
					<td width="15%" class="text-r" style="background-color:#f5f5f5">客户详细地址：</td>
					<td class="text-l" style="width:35%;">
						<input type="text" class="input-text" value="<{$detail.user_address}>" placeholder="客户详细地址" name="user_address">
					</td>
					<td width="15%" class="text-r" style="background-color:#f5f5f5">身份证：</td>
					<td class="text-l" style="width:35%;">
						<input type="text" class="input-text" value="<{$detail.user_idcard}>" placeholder="身份证" name="user_idcard">
					</td>				
			</tr>
			<tr class="text-c uhide">
					<td width="15%" class="text-r" style="background-color:#f5f5f5">联系电话：</td>
					<td class="text-l">
						<input type="text" class="input-text" value="<{$detail.user_phone}>" placeholder="联系电话" name="user_phone">
					</td>
					<td width="15%" class="text-r" style="background-color:#f5f5f5"></td>
					<td class="text-l">
					</td>					
			</tr>
		</tbody>
	</table>
	<button onclick="admin_open('添加商品','<{:U('goods',array('id'=>$detail['id']))}>','','1000','600')" class="btn btn-primary">
	添加商品</button>
	<table class="table table-border table-bordered table-hover table-bg">
		<thead>
			<tr>
				<th scope="col" colspan="11">商品列表</th>
			</tr>
			<tr class="text-c">
				<th width="40">ID</th>
				<th width="40">采购单编号</th>
				<th width="40">商品编码</th>
				<th width="40">商品名称</th>
				<th width="40">销售单价</th>
				<th width="40">数量</th>
				<th width="40">规格</th>
				<th width="40">原产国</th>
			</tr>
		</thead>
		<tbody>
			<volist name="list" id="vo">
			<tr class="text-c">
			 <input  name='gid' type="hidden" style="width:80px;" value="<{$vo['id']}>"/>
				<td><{$vo.id}></td>
				<td><span><{$detail.order_no}></span></td>

				<td><{$vo.goods_sn}></td>
				<td><{$vo.goods_name}></td>
				<td>
					<input  name='goods_price' type="input-text" style="width:80px;" value="<{$vo['goods_price']}>"/>
				</td>
				<td>
					<input  name='goods_nums' type="input-text" style="width:80px;" value="<{$vo['goods_nums']}>"/>
				</td>
				<td>
					<{$vo.spec}>
				</td>
				<td>
					 <select name="country_code" class="form-control selects" 
						 <volist name="country" id="vcc">
							<if condition="$vcc['country_code'] == $vo['source']">disabled="disabled"  style="width:130px;background:#ccc;"
							</if>
						 </volist>
					 >
                         <option value="">请选择</option>
                         <volist name="country" id="vcc">
                             <option value="<{$vcc.country_code}>" <if condition="$vcc['country_code'] == $vo['source']">selected</if>><{$vcc.country_name}></option>
                         </volist>
                     </select>
				</td>
			</tr>
			</volist>
		</tbody>
	</table>
	<input type="button" class="btn btn-primary radius mt" id="bedit" value="保存">
<div class="pages">
<{$page}>
</div>
</div>
<script type="text/javascript">
	$('#contacts_company_no').change(function(){
			if($(this).val()!=0){
				$(".uhide").hide();
			}else{
				$(".uhide").show();
			}
	})
    $(function(){
		if($("#contacts_company_no").val()!=0){
			$(".uhide").hide();
		}
		$(".transport_cate").change(function(){
			if($(this).val()==2){
				$('input[name=logistics_no]').show();
			}else{
				$('input[name=logistics_no]').hide();
			}
		});
		/*保存计划入库单数据*/
        $("#bedit").click(function(){
			var transport_cate=$('select[name=transport_cate]').val();
			var section_no=$('select[name=section_no]').val();
			var people_make_no=$('select[name=people_make_no]').val();
			var people_purchasing_no=$('select[name=people_purchasing_no]').val();
			var contacts_company_no=$('select[name=contacts_company_no]').val();
			var logistics_no=$('input[name=logistics_no]').val();
			
			var user_name=$('input[name=user_name]').val();
			var province=$('input[name=province]').val();
			var city=$('input[name=city]').val();
			var area=$('input[name=area]').val();
			var user_address=$('input[name=user_address]').val();
			var user_idcard=$('input[name=user_idcard]').val();
			var user_phone=$('input[name=user_phone]').val();
			
			if(section_no=="0"){
				layer.alert("申请部门不能为空");
				return false;
			}
			if(people_make_no=="0"){
				layer.alert("请选择制单人");
				return false;
			}
			if(people_purchasing_no=="0"){
				layer.alert("请选择采购申请人");
				return false;
			}
			if(contacts_company_no=='0'){
				if(user_name==""){
					layer.alert("客户姓名不能为空");
					return false;
				}
				if(province==""){
					layer.alert("省不能为空");
					return false;
				}
				if(city==""){
					layer.alert("市不能为空");
					return false;
				}
				if(area==""){
					layer.alert("区/县不能为空");
					return false;
				}
				if(user_address==""){
					layer.alert("客户详细地址不能为空");
					return false;
				}
				<!-- if(user_idcard==""){ -->
					<!-- layer.alert("身份证不能为空"); -->
					<!-- return false; -->
				<!-- } -->
				if(user_phone==""){
					layer.alert("联系电话不能为空");
					return false;
				}
			}
			
			var count=$('input[name=gid]').length;
			var gid=$('input[name=gid]');
			var goods_price=$('input[name=goods_price]');
			var goods_nums=$('input[name=goods_nums]');
			var selects=$(".selects");
			var str='';
			for(var i=0;i<count;i++){
				if(goods_price.eq(i).val()==0){
					layer.msg('销售单价不能为0');
					return false;
				}
				if(goods_nums.eq(i).val()==0){
					layer.msg('数量不能为0');
					return false;
				}

				var ss=selects.eq(i).find("option:selected").val();
				if(ss==''){
					layer.msg('请选择原产国');
					return false;
				}
				
				if(i==0){
					str=str+gid.eq(i).val()+":"+goods_price.eq(i).val()+":"+goods_nums.eq(i).val()+":"+ss;
				}else{
					str=str+","+gid.eq(i).val()+":"+goods_price.eq(i).val()+":"+goods_nums.eq(i).val()+":"+ss;
				}
			}
			$.ajax({
                type: 'POST',
                data: {
						id:<{:I('id')}>,
						section_no: section_no,
						people_make_no: people_make_no,
						people_purchasing_no: people_purchasing_no,
						contacts_company_no: contacts_company_no,
						transport_cate:transport_cate,
						logistics_no: logistics_no,
						user_name: user_name,
						province: province,
						city: city,
						area: area,
						user_address: user_address,
						user_idcard: user_idcard,
						user_phone: user_phone,
						strss:str
					  },
                url: "<{:U('edt')}>",
                success:function(data){
                    layer.msg(data.info,function(){
						if(data.status==0){
							return false;
						}else{
							self.window.location.href =self.window.location.href;
						}
						
					});
                }
            })
        });
    })
</script>
</body>
</html>
</html>